

package jetbrains.buildServer.server.rest.util;

import jetbrains.buildServer.ServiceLocator;
import jetbrains.buildServer.ServiceNotFoundException;
import jetbrains.buildServer.server.rest.ApiUrlBuilder;
import org.jetbrains.annotations.NotNull;

/**
 * @author Yegor.Yarko
 * Date: 20.04.13
 */
public class BeanContext {
  @NotNull private final ServiceLocator myServiceLocator;
  @NotNull private final ApiUrlBuilder myApiUrlBuilder;

  public BeanContext(
    BeanFactory factory,
    @NotNull ServiceLocator serviceLocator,
    @NotNull ApiUrlBuilder apiUrlBuilder
  ) {
    this(serviceLocator, apiUrlBuilder);
  }

  public BeanContext(
    @NotNull ServiceLocator serviceLocator,
    @NotNull ApiUrlBuilder apiUrlBuilder
  ) {
    myServiceLocator = serviceLocator;
    myApiUrlBuilder = apiUrlBuilder;
  }

  @NotNull
  public <T> T getSingletonService(@NotNull Class<T> serviceClass) throws ServiceNotFoundException {
    return myServiceLocator.getSingletonService(serviceClass);
  }

  @NotNull
  public ApiUrlBuilder getApiUrlBuilder(){
        return myApiUrlBuilder;
  }

  @NotNull
  public ServiceLocator getServiceLocator(){
        return myServiceLocator;
  }

}